{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Code to find intersections of ICESat-2 and ATM data\n",
    "\n",
    "**by Allison Chartrand**\n",
    "\n",
    "**June 2019 ICESat-2 Hackweek**\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [],
   "source": [
    "#IMPORT PACKAGES\n",
    "import os\n",
    "import glob\n",
    "import pandas as pd\n",
    "import csv\n",
    "import numpy as np\n",
    "import math\n",
    "import matplotlib.pyplot as plt\n",
    "import pyproj\n",
    "from scipy.spatial import distance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib widget"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Import Data**\n",
    "\n",
    "Get ATL06 data and put into dataframe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [],
   "source": [
    "ATL06filename = '~/xtrak/data_prod/ZachISatData_wSmoooth.csv'\n",
    "ATMfilename = '~/xtrak/data_prod/ATMproof_20140429_wSmooth_ac.csv'\n",
    "\n",
    "OutputFilename = '~/xtrak/data_prod/InterX_ATM2014_AllSmooth.csv'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>lon</th>\n",
       "      <th>lat</th>\n",
       "      <th>h</th>\n",
       "      <th>track</th>\n",
       "      <th>date</th>\n",
       "      <th>x</th>\n",
       "      <th>y</th>\n",
       "      <th>hSm</th>\n",
       "      <th>hSupSm</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-22.520585</td>\n",
       "      <td>78.700068</td>\n",
       "      <td>579.33765</td>\n",
       "      <td>gt3r</td>\n",
       "      <td>2019-01-04 12:24:25</td>\n",
       "      <td>469494.782922</td>\n",
       "      <td>-1.134613e+06</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-22.520755</td>\n",
       "      <td>78.700244</td>\n",
       "      <td>579.03015</td>\n",
       "      <td>gt3r</td>\n",
       "      <td>2019-01-04 12:24:25</td>\n",
       "      <td>469484.057930</td>\n",
       "      <td>-1.134597e+06</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-22.520925</td>\n",
       "      <td>78.700420</td>\n",
       "      <td>578.78815</td>\n",
       "      <td>gt3r</td>\n",
       "      <td>2019-01-04 12:24:25</td>\n",
       "      <td>469473.331404</td>\n",
       "      <td>-1.134581e+06</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-22.521094</td>\n",
       "      <td>78.700596</td>\n",
       "      <td>578.57214</td>\n",
       "      <td>gt3r</td>\n",
       "      <td>2019-01-04 12:24:25</td>\n",
       "      <td>469462.614457</td>\n",
       "      <td>-1.134564e+06</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-22.521264</td>\n",
       "      <td>78.700773</td>\n",
       "      <td>578.33830</td>\n",
       "      <td>gt3r</td>\n",
       "      <td>2019-01-04 12:24:25</td>\n",
       "      <td>469451.884907</td>\n",
       "      <td>-1.134548e+06</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         lon        lat          h track                date              x  \\\n",
       "0 -22.520585  78.700068  579.33765  gt3r 2019-01-04 12:24:25  469494.782922   \n",
       "1 -22.520755  78.700244  579.03015  gt3r 2019-01-04 12:24:25  469484.057930   \n",
       "2 -22.520925  78.700420  578.78815  gt3r 2019-01-04 12:24:25  469473.331404   \n",
       "3 -22.521094  78.700596  578.57214  gt3r 2019-01-04 12:24:25  469462.614457   \n",
       "4 -22.521264  78.700773  578.33830  gt3r 2019-01-04 12:24:25  469451.884907   \n",
       "\n",
       "              y  hSm  hSupSm  \n",
       "0 -1.134613e+06  NaN     NaN  \n",
       "1 -1.134597e+06  NaN     NaN  \n",
       "2 -1.134581e+06  NaN     NaN  \n",
       "3 -1.134564e+06  NaN     NaN  \n",
       "4 -1.134548e+06  NaN     NaN  "
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ATL06data = pd.read_csv(ATL06filename,parse_dates=[4])\n",
    "ATL06data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Get target points from ATM csv and put into dataframe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>ATM_lat</th>\n",
       "      <th>ATM_long</th>\n",
       "      <th>PS_x</th>\n",
       "      <th>PS_y</th>\n",
       "      <th>ATM_elev</th>\n",
       "      <th>dist_along</th>\n",
       "      <th>slope_NS</th>\n",
       "      <th>slope_EW</th>\n",
       "      <th>ATM_elev_Sm</th>\n",
       "      <th>ATM_elev_SupSm</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>79.150302</td>\n",
       "      <td>335.663786</td>\n",
       "      <td>415944.317386</td>\n",
       "      <td>-1.102872e+06</td>\n",
       "      <td>883.1842</td>\n",
       "      <td>18036.512689</td>\n",
       "      <td>-0.006359</td>\n",
       "      <td>-0.009239</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>79.150190</td>\n",
       "      <td>335.665218</td>\n",
       "      <td>415976.200234</td>\n",
       "      <td>-1.102873e+06</td>\n",
       "      <td>883.0373</td>\n",
       "      <td>18068.412960</td>\n",
       "      <td>-0.005456</td>\n",
       "      <td>-0.006168</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>79.150078</td>\n",
       "      <td>335.666651</td>\n",
       "      <td>416008.102644</td>\n",
       "      <td>-1.102874e+06</td>\n",
       "      <td>882.8962</td>\n",
       "      <td>18100.332515</td>\n",
       "      <td>-0.003837</td>\n",
       "      <td>-0.006896</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>79.149967</td>\n",
       "      <td>335.668086</td>\n",
       "      <td>416040.005299</td>\n",
       "      <td>-1.102875e+06</td>\n",
       "      <td>882.7560</td>\n",
       "      <td>18132.248675</td>\n",
       "      <td>-0.004822</td>\n",
       "      <td>-0.005571</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>79.149855</td>\n",
       "      <td>335.669519</td>\n",
       "      <td>416071.908333</td>\n",
       "      <td>-1.102876e+06</td>\n",
       "      <td>882.5889</td>\n",
       "      <td>18164.168794</td>\n",
       "      <td>-0.003373</td>\n",
       "      <td>-0.009250</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Unnamed: 0    ATM_lat    ATM_long           PS_x          PS_y  ATM_elev  \\\n",
       "0           0  79.150302  335.663786  415944.317386 -1.102872e+06  883.1842   \n",
       "1           1  79.150190  335.665218  415976.200234 -1.102873e+06  883.0373   \n",
       "2           2  79.150078  335.666651  416008.102644 -1.102874e+06  882.8962   \n",
       "3           3  79.149967  335.668086  416040.005299 -1.102875e+06  882.7560   \n",
       "4           4  79.149855  335.669519  416071.908333 -1.102876e+06  882.5889   \n",
       "\n",
       "     dist_along  slope_NS  slope_EW  ATM_elev_Sm  ATM_elev_SupSm  \n",
       "0  18036.512689 -0.006359 -0.009239          NaN             NaN  \n",
       "1  18068.412960 -0.005456 -0.006168          NaN             NaN  \n",
       "2  18100.332515 -0.003837 -0.006896          NaN             NaN  \n",
       "3  18132.248675 -0.004822 -0.005571          NaN             NaN  \n",
       "4  18164.168794 -0.003373 -0.009250          NaN             NaN  "
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ATMdata = pd.read_csv(ATMfilename)\n",
    "\n",
    "tpoints = ATMdata[['PS_x','PS_y']].copy()\n",
    "tpoints = tpoints.values\n",
    "ATMdata.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Define nearest neighbor algorithm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [],
   "source": [
    "def closest_node(node, nodes):\n",
    "    closest_index = distance.cdist([node], nodes).argmin()\n",
    "    closest_dist = np.min(distance.cdist([node], nodes,'euclidean'))\n",
    "    return closest_index, closest_dist"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Make an empty dataframe for intersections\n",
    "Get query points from ATL06 csv and put into dataframe\n",
    "Loop through unique dates and ground tracks and find the closest point between each ground track and the flowline\n",
    "Store intersection along-flow distance, z_ATM, z_ATL06 and other helpful data in Intersections dataframe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [],
   "source": [
    "Intersections = {'dist_along':[],'ATM_elev':[],'idx_ATM':[],'z_ATL06':[],'t_ATL06':[],'idx_ATL06':[],'gt_ATL06':[]}\n",
    "Intersections = pd.DataFrame(data = Intersections)\n",
    "i = 0\n",
    "for day in ATL06data.date.unique():\n",
    "\n",
    "    for tr in ATL06data.track.unique():\n",
    "        close_idx = []\n",
    "        min_dist = []\n",
    "        AddDatarow = []\n",
    "\n",
    "        #dfTran is a single radar transect\n",
    "        dfTran = ATL06data.query('date == @day & track == @tr')\n",
    "        if dfTran.shape[0] == 0:\n",
    "            continue\n",
    "            \n",
    "        \n",
    "        qpoints = dfTran[['x','y']].copy()\n",
    "        qpoints = qpoints.values\n",
    "\n",
    "        \n",
    "        for j in range(len(tpoints)):\n",
    "            close_idxT,min_distT = closest_node(tpoints[j,:], qpoints)\n",
    "            close_idx = np.append(close_idx,[close_idxT])\n",
    "            min_dist = np.append(min_dist,[min_distT])\n",
    "        if min(min_dist) > 1000:\n",
    "            continue\n",
    "        \n",
    "        tpt_idx = np.argmin(min_dist)\n",
    "        qpt_idx = int(close_idx[tpt_idx])\n",
    "        dfTran_idx = dfTran.loc[dfTran['date'] == day].index[0]\n",
    "        qpt_idx = qpt_idx+dfTran_idx\n",
    "        \n",
    "        AddDatarow = {'dist_along':[ATMdata.loc[tpt_idx,'dist_along']],\n",
    "                      'ATM_elev':[ATMdata.loc[tpt_idx,'ATM_elev_SupSm']],\n",
    "                      'idx_ATM':[tpt_idx],\n",
    "                      'z_ATL06':[dfTran.loc[qpt_idx,'hSupSm']],\n",
    "                      't_ATL06':[dfTran.loc[qpt_idx,'date']],\n",
    "                      'idx_ATL06':[qpt_idx],\n",
    "                      'gt_ATL06':[dfTran.loc[qpt_idx,'track']]}\n",
    "        AddDatarow = pd.DataFrame(data = AddDatarow)\n",
    "        Intersections = Intersections.append(AddDatarow,ignore_index=True)\n",
    "#         Intersections.reset_index(drop=True)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>dist_along</th>\n",
       "      <th>ATM_elev</th>\n",
       "      <th>idx_ATM</th>\n",
       "      <th>z_ATL06</th>\n",
       "      <th>t_ATL06</th>\n",
       "      <th>idx_ATL06</th>\n",
       "      <th>gt_ATL06</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>125289.795232</td>\n",
       "      <td>38.49300</td>\n",
       "      <td>3213.0</td>\n",
       "      <td>35.501406</td>\n",
       "      <td>2019-02-15 10:09:55</td>\n",
       "      <td>1576.0</td>\n",
       "      <td>gt1l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>125354.749926</td>\n",
       "      <td>38.22330</td>\n",
       "      <td>3215.0</td>\n",
       "      <td>34.084645</td>\n",
       "      <td>2019-02-15 10:09:55</td>\n",
       "      <td>4931.0</td>\n",
       "      <td>gt1r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>96208.910678</td>\n",
       "      <td>90.80875</td>\n",
       "      <td>2367.0</td>\n",
       "      <td>69.272560</td>\n",
       "      <td>2019-01-16 01:09:49</td>\n",
       "      <td>39474.0</td>\n",
       "      <td>gt3r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>102696.987249</td>\n",
       "      <td>27.22505</td>\n",
       "      <td>2566.0</td>\n",
       "      <td>28.789461</td>\n",
       "      <td>2019-01-16 01:09:49</td>\n",
       "      <td>19999.0</td>\n",
       "      <td>gt1l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>102632.054028</td>\n",
       "      <td>27.14045</td>\n",
       "      <td>2564.0</td>\n",
       "      <td>29.224519</td>\n",
       "      <td>2019-01-16 01:09:49</td>\n",
       "      <td>23921.0</td>\n",
       "      <td>gt1r</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      dist_along  ATM_elev  idx_ATM    z_ATL06             t_ATL06  idx_ATL06  \\\n",
       "0  125289.795232  38.49300   3213.0  35.501406 2019-02-15 10:09:55     1576.0   \n",
       "1  125354.749926  38.22330   3215.0  34.084645 2019-02-15 10:09:55     4931.0   \n",
       "2   96208.910678  90.80875   2367.0  69.272560 2019-01-16 01:09:49    39474.0   \n",
       "3  102696.987249  27.22505   2566.0  28.789461 2019-01-16 01:09:49    19999.0   \n",
       "4  102632.054028  27.14045   2564.0  29.224519 2019-01-16 01:09:49    23921.0   \n",
       "\n",
       "  gt_ATL06  \n",
       "0     gt1l  \n",
       "1     gt1r  \n",
       "2     gt3r  \n",
       "3     gt1l  \n",
       "4     gt1r  "
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Intersections.head()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Plot "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "732a7ac356f4462f8ad36ac9c25d5197",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "FigureCanvasNbAgg()"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.colorbar.Colorbar at 0x7fe2d7b24278>"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f, ax = plt.subplots()\n",
    "plt.scatter(Intersections['dist_along']/1000,Intersections['z_ATL06'],c=Intersections['t_ATL06'])\n",
    "# ax.scatter(Intersections['dist_along']/1000,Intersections['z_ATL06'],Intersections['t_ATL06'])\n",
    "# ax.scatter(Intersections['dist_along']/1000,Intersections['z_ATL06'], c = Time,s=1)\n",
    "plt.plot(Intersections['dist_along']/1000,Intersections['ATM_elev'],'.')\n",
    "# cb = f.colorbar()\n",
    "plt.colorbar()\n",
    "\n",
    "# cb.ax.set_yticklabels(df.index.strftime('%b %Y'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.close('all')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Sort the data by date and track"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>index</th>\n",
       "      <th>dist_along</th>\n",
       "      <th>ATM_elev</th>\n",
       "      <th>idx_ATM</th>\n",
       "      <th>z_ATL06</th>\n",
       "      <th>t_ATL06</th>\n",
       "      <th>idx_ATL06</th>\n",
       "      <th>gt_ATL06</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>161</td>\n",
       "      <td>122581.170689</td>\n",
       "      <td>45.04805</td>\n",
       "      <td>3130.0</td>\n",
       "      <td>42.769034</td>\n",
       "      <td>2018-10-18 15:53:52</td>\n",
       "      <td>617767.0</td>\n",
       "      <td>gt1l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>162</td>\n",
       "      <td>122647.058967</td>\n",
       "      <td>44.76880</td>\n",
       "      <td>3132.0</td>\n",
       "      <td>42.156155</td>\n",
       "      <td>2018-10-18 15:53:52</td>\n",
       "      <td>621074.0</td>\n",
       "      <td>gt1r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>163</td>\n",
       "      <td>125810.129706</td>\n",
       "      <td>36.67925</td>\n",
       "      <td>3229.0</td>\n",
       "      <td>34.448452</td>\n",
       "      <td>2018-10-18 15:53:52</td>\n",
       "      <td>624012.0</td>\n",
       "      <td>gt2l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>164</td>\n",
       "      <td>125875.304455</td>\n",
       "      <td>36.28405</td>\n",
       "      <td>3231.0</td>\n",
       "      <td>32.827094</td>\n",
       "      <td>2018-10-18 15:53:52</td>\n",
       "      <td>626687.0</td>\n",
       "      <td>gt2r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>52</td>\n",
       "      <td>80573.944294</td>\n",
       "      <td>295.06470</td>\n",
       "      <td>1901.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2018-10-21 05:21:45</td>\n",
       "      <td>205271.0</td>\n",
       "      <td>gt2r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>51</td>\n",
       "      <td>77393.293766</td>\n",
       "      <td>269.78040</td>\n",
       "      <td>1803.0</td>\n",
       "      <td>255.108995</td>\n",
       "      <td>2018-10-21 05:21:45</td>\n",
       "      <td>205803.0</td>\n",
       "      <td>gt3r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>103</td>\n",
       "      <td>67655.902876</td>\n",
       "      <td>416.97825</td>\n",
       "      <td>1538.0</td>\n",
       "      <td>361.948000</td>\n",
       "      <td>2018-10-25 05:13:27</td>\n",
       "      <td>398282.0</td>\n",
       "      <td>gt1l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>104</td>\n",
       "      <td>67687.240097</td>\n",
       "      <td>415.62490</td>\n",
       "      <td>1539.0</td>\n",
       "      <td>391.111190</td>\n",
       "      <td>2018-10-25 05:13:27</td>\n",
       "      <td>400497.0</td>\n",
       "      <td>gt1r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>105</td>\n",
       "      <td>64607.360881</td>\n",
       "      <td>425.31270</td>\n",
       "      <td>1439.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2018-10-25 05:13:27</td>\n",
       "      <td>401953.0</td>\n",
       "      <td>gt2l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>106</td>\n",
       "      <td>64484.432996</td>\n",
       "      <td>425.31270</td>\n",
       "      <td>1435.0</td>\n",
       "      <td>410.575870</td>\n",
       "      <td>2018-10-25 05:13:27</td>\n",
       "      <td>403762.0</td>\n",
       "      <td>gt2r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>107</td>\n",
       "      <td>61379.685494</td>\n",
       "      <td>521.00925</td>\n",
       "      <td>1337.0</td>\n",
       "      <td>509.489320</td>\n",
       "      <td>2018-10-25 05:13:27</td>\n",
       "      <td>405087.0</td>\n",
       "      <td>gt3l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>102</td>\n",
       "      <td>61315.684441</td>\n",
       "      <td>521.22515</td>\n",
       "      <td>1335.0</td>\n",
       "      <td>509.782975</td>\n",
       "      <td>2018-10-25 05:13:27</td>\n",
       "      <td>406842.0</td>\n",
       "      <td>gt3r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>115</td>\n",
       "      <td>89377.265064</td>\n",
       "      <td>136.73470</td>\n",
       "      <td>2164.0</td>\n",
       "      <td>108.349335</td>\n",
       "      <td>2018-10-26 15:37:16</td>\n",
       "      <td>431219.0</td>\n",
       "      <td>gt1l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>116</td>\n",
       "      <td>89479.464606</td>\n",
       "      <td>136.41060</td>\n",
       "      <td>2167.0</td>\n",
       "      <td>107.119035</td>\n",
       "      <td>2018-10-26 15:37:16</td>\n",
       "      <td>435063.0</td>\n",
       "      <td>gt1r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>117</td>\n",
       "      <td>92780.627483</td>\n",
       "      <td>121.14320</td>\n",
       "      <td>2264.0</td>\n",
       "      <td>96.175800</td>\n",
       "      <td>2018-10-26 15:37:16</td>\n",
       "      <td>438910.0</td>\n",
       "      <td>gt2l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>118</td>\n",
       "      <td>92848.522698</td>\n",
       "      <td>120.88755</td>\n",
       "      <td>2266.0</td>\n",
       "      <td>97.067132</td>\n",
       "      <td>2018-10-26 15:37:16</td>\n",
       "      <td>442774.0</td>\n",
       "      <td>gt2r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>119</td>\n",
       "      <td>96176.153026</td>\n",
       "      <td>91.11945</td>\n",
       "      <td>2366.0</td>\n",
       "      <td>28.308387</td>\n",
       "      <td>2018-10-26 15:37:16</td>\n",
       "      <td>446614.0</td>\n",
       "      <td>gt3l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>114</td>\n",
       "      <td>96241.609114</td>\n",
       "      <td>90.38570</td>\n",
       "      <td>2368.0</td>\n",
       "      <td>28.727420</td>\n",
       "      <td>2018-10-26 15:37:16</td>\n",
       "      <td>450516.0</td>\n",
       "      <td>gt3r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>172</td>\n",
       "      <td>121954.028971</td>\n",
       "      <td>45.61400</td>\n",
       "      <td>3111.0</td>\n",
       "      <td>44.933040</td>\n",
       "      <td>2018-11-11 04:14:44</td>\n",
       "      <td>651541.0</td>\n",
       "      <td>gt1l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>173</td>\n",
       "      <td>121854.851720</td>\n",
       "      <td>45.61400</td>\n",
       "      <td>3108.0</td>\n",
       "      <td>44.027002</td>\n",
       "      <td>2018-11-11 04:14:44</td>\n",
       "      <td>654324.0</td>\n",
       "      <td>gt1r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>174</td>\n",
       "      <td>118653.494370</td>\n",
       "      <td>41.70600</td>\n",
       "      <td>3034.0</td>\n",
       "      <td>38.935440</td>\n",
       "      <td>2018-11-11 04:14:44</td>\n",
       "      <td>657927.0</td>\n",
       "      <td>gt2l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>175</td>\n",
       "      <td>118588.415511</td>\n",
       "      <td>41.09350</td>\n",
       "      <td>3032.0</td>\n",
       "      <td>40.171133</td>\n",
       "      <td>2018-11-11 04:14:44</td>\n",
       "      <td>661532.0</td>\n",
       "      <td>gt2r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>176</td>\n",
       "      <td>115361.066547</td>\n",
       "      <td>27.20825</td>\n",
       "      <td>2934.0</td>\n",
       "      <td>28.129115</td>\n",
       "      <td>2018-11-11 04:14:44</td>\n",
       "      <td>665513.0</td>\n",
       "      <td>gt3l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>171</td>\n",
       "      <td>115295.191381</td>\n",
       "      <td>27.20825</td>\n",
       "      <td>2932.0</td>\n",
       "      <td>28.052530</td>\n",
       "      <td>2018-11-11 04:14:44</td>\n",
       "      <td>669478.0</td>\n",
       "      <td>gt3r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>84</td>\n",
       "      <td>105596.029174</td>\n",
       "      <td>27.06520</td>\n",
       "      <td>2637.0</td>\n",
       "      <td>28.661966</td>\n",
       "      <td>2018-11-15 04:06:22</td>\n",
       "      <td>330937.0</td>\n",
       "      <td>gt1l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>85</td>\n",
       "      <td>105001.339697</td>\n",
       "      <td>27.06980</td>\n",
       "      <td>2636.0</td>\n",
       "      <td>29.297360</td>\n",
       "      <td>2018-11-15 04:06:22</td>\n",
       "      <td>334883.0</td>\n",
       "      <td>gt1r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>86</td>\n",
       "      <td>102145.248209</td>\n",
       "      <td>27.05085</td>\n",
       "      <td>2549.0</td>\n",
       "      <td>28.851150</td>\n",
       "      <td>2018-11-15 04:06:22</td>\n",
       "      <td>338759.0</td>\n",
       "      <td>gt2l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>87</td>\n",
       "      <td>102080.404536</td>\n",
       "      <td>27.04725</td>\n",
       "      <td>2547.0</td>\n",
       "      <td>29.350223</td>\n",
       "      <td>2018-11-15 04:06:22</td>\n",
       "      <td>342697.0</td>\n",
       "      <td>gt2r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>88</td>\n",
       "      <td>98960.114430</td>\n",
       "      <td>28.28555</td>\n",
       "      <td>2451.0</td>\n",
       "      <td>68.897153</td>\n",
       "      <td>2018-11-15 04:06:22</td>\n",
       "      <td>346606.0</td>\n",
       "      <td>gt3l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>83</td>\n",
       "      <td>98894.603155</td>\n",
       "      <td>31.01350</td>\n",
       "      <td>2449.0</td>\n",
       "      <td>67.444460</td>\n",
       "      <td>2018-11-15 04:06:22</td>\n",
       "      <td>350504.0</td>\n",
       "      <td>gt3r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159</th>\n",
       "      <td>168</td>\n",
       "      <td>121425.520431</td>\n",
       "      <td>45.61400</td>\n",
       "      <td>3095.0</td>\n",
       "      <td>45.429640</td>\n",
       "      <td>2019-02-09 23:54:28</td>\n",
       "      <td>638427.0</td>\n",
       "      <td>gt2l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>160</th>\n",
       "      <td>169</td>\n",
       "      <td>121359.531822</td>\n",
       "      <td>45.61400</td>\n",
       "      <td>3093.0</td>\n",
       "      <td>45.324902</td>\n",
       "      <td>2019-02-09 23:54:28</td>\n",
       "      <td>641333.0</td>\n",
       "      <td>gt2r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>161</th>\n",
       "      <td>170</td>\n",
       "      <td>118164.360812</td>\n",
       "      <td>40.06585</td>\n",
       "      <td>3019.0</td>\n",
       "      <td>40.598112</td>\n",
       "      <td>2019-02-09 23:54:28</td>\n",
       "      <td>645057.0</td>\n",
       "      <td>gt3l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>162</th>\n",
       "      <td>165</td>\n",
       "      <td>118098.943857</td>\n",
       "      <td>39.76175</td>\n",
       "      <td>3017.0</td>\n",
       "      <td>39.578097</td>\n",
       "      <td>2019-02-09 23:54:28</td>\n",
       "      <td>648792.0</td>\n",
       "      <td>gt3r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>163</th>\n",
       "      <td>109</td>\n",
       "      <td>108153.357245</td>\n",
       "      <td>27.06205</td>\n",
       "      <td>2715.0</td>\n",
       "      <td>28.418760</td>\n",
       "      <td>2019-02-13 23:46:06</td>\n",
       "      <td>409992.0</td>\n",
       "      <td>gt1l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>164</th>\n",
       "      <td>110</td>\n",
       "      <td>108088.013034</td>\n",
       "      <td>27.05840</td>\n",
       "      <td>2713.0</td>\n",
       "      <td>28.504448</td>\n",
       "      <td>2019-02-13 23:46:06</td>\n",
       "      <td>413583.0</td>\n",
       "      <td>gt1r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>165</th>\n",
       "      <td>111</td>\n",
       "      <td>104835.607040</td>\n",
       "      <td>27.07685</td>\n",
       "      <td>2631.0</td>\n",
       "      <td>27.828007</td>\n",
       "      <td>2019-02-13 23:46:06</td>\n",
       "      <td>417329.0</td>\n",
       "      <td>gt2l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>166</th>\n",
       "      <td>112</td>\n",
       "      <td>104769.182503</td>\n",
       "      <td>27.07685</td>\n",
       "      <td>2629.0</td>\n",
       "      <td>27.948965</td>\n",
       "      <td>2019-02-13 23:46:06</td>\n",
       "      <td>421050.0</td>\n",
       "      <td>gt2r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>167</th>\n",
       "      <td>113</td>\n",
       "      <td>101658.707466</td>\n",
       "      <td>27.03075</td>\n",
       "      <td>2534.0</td>\n",
       "      <td>30.119713</td>\n",
       "      <td>2019-02-13 23:46:06</td>\n",
       "      <td>424890.0</td>\n",
       "      <td>gt3l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>168</th>\n",
       "      <td>108</td>\n",
       "      <td>101593.796438</td>\n",
       "      <td>27.02715</td>\n",
       "      <td>2532.0</td>\n",
       "      <td>31.139245</td>\n",
       "      <td>2019-02-13 23:46:06</td>\n",
       "      <td>428679.0</td>\n",
       "      <td>gt3r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>169</th>\n",
       "      <td>0</td>\n",
       "      <td>125289.795232</td>\n",
       "      <td>38.49300</td>\n",
       "      <td>3213.0</td>\n",
       "      <td>35.501406</td>\n",
       "      <td>2019-02-15 10:09:55</td>\n",
       "      <td>1576.0</td>\n",
       "      <td>gt1l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>170</th>\n",
       "      <td>1</td>\n",
       "      <td>125354.749926</td>\n",
       "      <td>38.22330</td>\n",
       "      <td>3215.0</td>\n",
       "      <td>34.084645</td>\n",
       "      <td>2019-02-15 10:09:55</td>\n",
       "      <td>4931.0</td>\n",
       "      <td>gt1r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>171</th>\n",
       "      <td>37</td>\n",
       "      <td>91929.771598</td>\n",
       "      <td>124.99810</td>\n",
       "      <td>2239.0</td>\n",
       "      <td>95.879260</td>\n",
       "      <td>2019-02-17 23:37:46</td>\n",
       "      <td>146166.0</td>\n",
       "      <td>gt1l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>172</th>\n",
       "      <td>38</td>\n",
       "      <td>91861.692774</td>\n",
       "      <td>125.58635</td>\n",
       "      <td>2237.0</td>\n",
       "      <td>96.905113</td>\n",
       "      <td>2019-02-17 23:37:46</td>\n",
       "      <td>150060.0</td>\n",
       "      <td>gt1r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>173</th>\n",
       "      <td>39</td>\n",
       "      <td>88729.738750</td>\n",
       "      <td>138.20130</td>\n",
       "      <td>2145.0</td>\n",
       "      <td>111.239910</td>\n",
       "      <td>2019-02-17 23:37:46</td>\n",
       "      <td>153999.0</td>\n",
       "      <td>gt2l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>174</th>\n",
       "      <td>40</td>\n",
       "      <td>88661.510375</td>\n",
       "      <td>138.20130</td>\n",
       "      <td>2143.0</td>\n",
       "      <td>112.087285</td>\n",
       "      <td>2019-02-17 23:37:46</td>\n",
       "      <td>157948.0</td>\n",
       "      <td>gt2r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>175</th>\n",
       "      <td>41</td>\n",
       "      <td>85556.001064</td>\n",
       "      <td>130.02795</td>\n",
       "      <td>2052.0</td>\n",
       "      <td>100.608815</td>\n",
       "      <td>2019-02-17 23:37:46</td>\n",
       "      <td>161878.0</td>\n",
       "      <td>gt3l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>176</th>\n",
       "      <td>36</td>\n",
       "      <td>85454.321057</td>\n",
       "      <td>130.08550</td>\n",
       "      <td>2049.0</td>\n",
       "      <td>98.365062</td>\n",
       "      <td>2019-02-17 23:37:46</td>\n",
       "      <td>165795.0</td>\n",
       "      <td>gt3r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>177</th>\n",
       "      <td>150</td>\n",
       "      <td>109036.355948</td>\n",
       "      <td>27.06775</td>\n",
       "      <td>2742.0</td>\n",
       "      <td>28.824031</td>\n",
       "      <td>2019-02-19 10:01:34</td>\n",
       "      <td>570845.0</td>\n",
       "      <td>gt1l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>178</th>\n",
       "      <td>151</td>\n",
       "      <td>109134.723785</td>\n",
       "      <td>27.06980</td>\n",
       "      <td>2745.0</td>\n",
       "      <td>28.788947</td>\n",
       "      <td>2019-02-19 10:01:34</td>\n",
       "      <td>574757.0</td>\n",
       "      <td>gt1r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>179</th>\n",
       "      <td>152</td>\n",
       "      <td>112275.636373</td>\n",
       "      <td>27.09870</td>\n",
       "      <td>2840.0</td>\n",
       "      <td>28.207432</td>\n",
       "      <td>2019-02-19 10:01:34</td>\n",
       "      <td>578726.0</td>\n",
       "      <td>gt2l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>180</th>\n",
       "      <td>153</td>\n",
       "      <td>112341.684666</td>\n",
       "      <td>27.09930</td>\n",
       "      <td>2842.0</td>\n",
       "      <td>28.204486</td>\n",
       "      <td>2019-02-19 10:01:34</td>\n",
       "      <td>582689.0</td>\n",
       "      <td>gt2r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>181</th>\n",
       "      <td>154</td>\n",
       "      <td>115492.850024</td>\n",
       "      <td>27.21200</td>\n",
       "      <td>2938.0</td>\n",
       "      <td>28.316190</td>\n",
       "      <td>2019-02-19 10:01:34</td>\n",
       "      <td>586663.0</td>\n",
       "      <td>gt3l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>182</th>\n",
       "      <td>149</td>\n",
       "      <td>115591.706990</td>\n",
       "      <td>27.21215</td>\n",
       "      <td>2941.0</td>\n",
       "      <td>28.303164</td>\n",
       "      <td>2019-02-19 10:01:34</td>\n",
       "      <td>590579.0</td>\n",
       "      <td>gt3r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>183</th>\n",
       "      <td>178</td>\n",
       "      <td>92270.364511</td>\n",
       "      <td>124.08030</td>\n",
       "      <td>2249.0</td>\n",
       "      <td>93.113032</td>\n",
       "      <td>2019-02-23 09:53:16</td>\n",
       "      <td>671953.0</td>\n",
       "      <td>gt1l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>184</th>\n",
       "      <td>179</td>\n",
       "      <td>92338.479124</td>\n",
       "      <td>123.68205</td>\n",
       "      <td>2251.0</td>\n",
       "      <td>86.354335</td>\n",
       "      <td>2019-02-23 09:53:16</td>\n",
       "      <td>675852.0</td>\n",
       "      <td>gt1r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>185</th>\n",
       "      <td>180</td>\n",
       "      <td>95651.996664</td>\n",
       "      <td>94.41245</td>\n",
       "      <td>2350.0</td>\n",
       "      <td>82.014457</td>\n",
       "      <td>2019-02-23 09:53:16</td>\n",
       "      <td>679715.0</td>\n",
       "      <td>gt2l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>186</th>\n",
       "      <td>181</td>\n",
       "      <td>95717.578915</td>\n",
       "      <td>94.06105</td>\n",
       "      <td>2352.0</td>\n",
       "      <td>80.106848</td>\n",
       "      <td>2019-02-23 09:53:16</td>\n",
       "      <td>683572.0</td>\n",
       "      <td>gt2r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>187</th>\n",
       "      <td>182</td>\n",
       "      <td>98960.114430</td>\n",
       "      <td>28.28555</td>\n",
       "      <td>2451.0</td>\n",
       "      <td>32.379897</td>\n",
       "      <td>2019-02-23 09:53:16</td>\n",
       "      <td>687446.0</td>\n",
       "      <td>gt3l</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>188</th>\n",
       "      <td>177</td>\n",
       "      <td>99025.590148</td>\n",
       "      <td>27.16090</td>\n",
       "      <td>2453.0</td>\n",
       "      <td>34.729114</td>\n",
       "      <td>2019-02-23 09:53:16</td>\n",
       "      <td>691356.0</td>\n",
       "      <td>gt3r</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>189 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     index     dist_along   ATM_elev  idx_ATM     z_ATL06             t_ATL06  \\\n",
       "0      161  122581.170689   45.04805   3130.0   42.769034 2018-10-18 15:53:52   \n",
       "1      162  122647.058967   44.76880   3132.0   42.156155 2018-10-18 15:53:52   \n",
       "2      163  125810.129706   36.67925   3229.0   34.448452 2018-10-18 15:53:52   \n",
       "3      164  125875.304455   36.28405   3231.0   32.827094 2018-10-18 15:53:52   \n",
       "4       52   80573.944294  295.06470   1901.0         NaN 2018-10-21 05:21:45   \n",
       "5       51   77393.293766  269.78040   1803.0  255.108995 2018-10-21 05:21:45   \n",
       "6      103   67655.902876  416.97825   1538.0  361.948000 2018-10-25 05:13:27   \n",
       "7      104   67687.240097  415.62490   1539.0  391.111190 2018-10-25 05:13:27   \n",
       "8      105   64607.360881  425.31270   1439.0         NaN 2018-10-25 05:13:27   \n",
       "9      106   64484.432996  425.31270   1435.0  410.575870 2018-10-25 05:13:27   \n",
       "10     107   61379.685494  521.00925   1337.0  509.489320 2018-10-25 05:13:27   \n",
       "11     102   61315.684441  521.22515   1335.0  509.782975 2018-10-25 05:13:27   \n",
       "12     115   89377.265064  136.73470   2164.0  108.349335 2018-10-26 15:37:16   \n",
       "13     116   89479.464606  136.41060   2167.0  107.119035 2018-10-26 15:37:16   \n",
       "14     117   92780.627483  121.14320   2264.0   96.175800 2018-10-26 15:37:16   \n",
       "15     118   92848.522698  120.88755   2266.0   97.067132 2018-10-26 15:37:16   \n",
       "16     119   96176.153026   91.11945   2366.0   28.308387 2018-10-26 15:37:16   \n",
       "17     114   96241.609114   90.38570   2368.0   28.727420 2018-10-26 15:37:16   \n",
       "18     172  121954.028971   45.61400   3111.0   44.933040 2018-11-11 04:14:44   \n",
       "19     173  121854.851720   45.61400   3108.0   44.027002 2018-11-11 04:14:44   \n",
       "20     174  118653.494370   41.70600   3034.0   38.935440 2018-11-11 04:14:44   \n",
       "21     175  118588.415511   41.09350   3032.0   40.171133 2018-11-11 04:14:44   \n",
       "22     176  115361.066547   27.20825   2934.0   28.129115 2018-11-11 04:14:44   \n",
       "23     171  115295.191381   27.20825   2932.0   28.052530 2018-11-11 04:14:44   \n",
       "24      84  105596.029174   27.06520   2637.0   28.661966 2018-11-15 04:06:22   \n",
       "25      85  105001.339697   27.06980   2636.0   29.297360 2018-11-15 04:06:22   \n",
       "26      86  102145.248209   27.05085   2549.0   28.851150 2018-11-15 04:06:22   \n",
       "27      87  102080.404536   27.04725   2547.0   29.350223 2018-11-15 04:06:22   \n",
       "28      88   98960.114430   28.28555   2451.0   68.897153 2018-11-15 04:06:22   \n",
       "29      83   98894.603155   31.01350   2449.0   67.444460 2018-11-15 04:06:22   \n",
       "..     ...            ...        ...      ...         ...                 ...   \n",
       "159    168  121425.520431   45.61400   3095.0   45.429640 2019-02-09 23:54:28   \n",
       "160    169  121359.531822   45.61400   3093.0   45.324902 2019-02-09 23:54:28   \n",
       "161    170  118164.360812   40.06585   3019.0   40.598112 2019-02-09 23:54:28   \n",
       "162    165  118098.943857   39.76175   3017.0   39.578097 2019-02-09 23:54:28   \n",
       "163    109  108153.357245   27.06205   2715.0   28.418760 2019-02-13 23:46:06   \n",
       "164    110  108088.013034   27.05840   2713.0   28.504448 2019-02-13 23:46:06   \n",
       "165    111  104835.607040   27.07685   2631.0   27.828007 2019-02-13 23:46:06   \n",
       "166    112  104769.182503   27.07685   2629.0   27.948965 2019-02-13 23:46:06   \n",
       "167    113  101658.707466   27.03075   2534.0   30.119713 2019-02-13 23:46:06   \n",
       "168    108  101593.796438   27.02715   2532.0   31.139245 2019-02-13 23:46:06   \n",
       "169      0  125289.795232   38.49300   3213.0   35.501406 2019-02-15 10:09:55   \n",
       "170      1  125354.749926   38.22330   3215.0   34.084645 2019-02-15 10:09:55   \n",
       "171     37   91929.771598  124.99810   2239.0   95.879260 2019-02-17 23:37:46   \n",
       "172     38   91861.692774  125.58635   2237.0   96.905113 2019-02-17 23:37:46   \n",
       "173     39   88729.738750  138.20130   2145.0  111.239910 2019-02-17 23:37:46   \n",
       "174     40   88661.510375  138.20130   2143.0  112.087285 2019-02-17 23:37:46   \n",
       "175     41   85556.001064  130.02795   2052.0  100.608815 2019-02-17 23:37:46   \n",
       "176     36   85454.321057  130.08550   2049.0   98.365062 2019-02-17 23:37:46   \n",
       "177    150  109036.355948   27.06775   2742.0   28.824031 2019-02-19 10:01:34   \n",
       "178    151  109134.723785   27.06980   2745.0   28.788947 2019-02-19 10:01:34   \n",
       "179    152  112275.636373   27.09870   2840.0   28.207432 2019-02-19 10:01:34   \n",
       "180    153  112341.684666   27.09930   2842.0   28.204486 2019-02-19 10:01:34   \n",
       "181    154  115492.850024   27.21200   2938.0   28.316190 2019-02-19 10:01:34   \n",
       "182    149  115591.706990   27.21215   2941.0   28.303164 2019-02-19 10:01:34   \n",
       "183    178   92270.364511  124.08030   2249.0   93.113032 2019-02-23 09:53:16   \n",
       "184    179   92338.479124  123.68205   2251.0   86.354335 2019-02-23 09:53:16   \n",
       "185    180   95651.996664   94.41245   2350.0   82.014457 2019-02-23 09:53:16   \n",
       "186    181   95717.578915   94.06105   2352.0   80.106848 2019-02-23 09:53:16   \n",
       "187    182   98960.114430   28.28555   2451.0   32.379897 2019-02-23 09:53:16   \n",
       "188    177   99025.590148   27.16090   2453.0   34.729114 2019-02-23 09:53:16   \n",
       "\n",
       "     idx_ATL06 gt_ATL06  \n",
       "0     617767.0     gt1l  \n",
       "1     621074.0     gt1r  \n",
       "2     624012.0     gt2l  \n",
       "3     626687.0     gt2r  \n",
       "4     205271.0     gt2r  \n",
       "5     205803.0     gt3r  \n",
       "6     398282.0     gt1l  \n",
       "7     400497.0     gt1r  \n",
       "8     401953.0     gt2l  \n",
       "9     403762.0     gt2r  \n",
       "10    405087.0     gt3l  \n",
       "11    406842.0     gt3r  \n",
       "12    431219.0     gt1l  \n",
       "13    435063.0     gt1r  \n",
       "14    438910.0     gt2l  \n",
       "15    442774.0     gt2r  \n",
       "16    446614.0     gt3l  \n",
       "17    450516.0     gt3r  \n",
       "18    651541.0     gt1l  \n",
       "19    654324.0     gt1r  \n",
       "20    657927.0     gt2l  \n",
       "21    661532.0     gt2r  \n",
       "22    665513.0     gt3l  \n",
       "23    669478.0     gt3r  \n",
       "24    330937.0     gt1l  \n",
       "25    334883.0     gt1r  \n",
       "26    338759.0     gt2l  \n",
       "27    342697.0     gt2r  \n",
       "28    346606.0     gt3l  \n",
       "29    350504.0     gt3r  \n",
       "..         ...      ...  \n",
       "159   638427.0     gt2l  \n",
       "160   641333.0     gt2r  \n",
       "161   645057.0     gt3l  \n",
       "162   648792.0     gt3r  \n",
       "163   409992.0     gt1l  \n",
       "164   413583.0     gt1r  \n",
       "165   417329.0     gt2l  \n",
       "166   421050.0     gt2r  \n",
       "167   424890.0     gt3l  \n",
       "168   428679.0     gt3r  \n",
       "169     1576.0     gt1l  \n",
       "170     4931.0     gt1r  \n",
       "171   146166.0     gt1l  \n",
       "172   150060.0     gt1r  \n",
       "173   153999.0     gt2l  \n",
       "174   157948.0     gt2r  \n",
       "175   161878.0     gt3l  \n",
       "176   165795.0     gt3r  \n",
       "177   570845.0     gt1l  \n",
       "178   574757.0     gt1r  \n",
       "179   578726.0     gt2l  \n",
       "180   582689.0     gt2r  \n",
       "181   586663.0     gt3l  \n",
       "182   590579.0     gt3r  \n",
       "183   671953.0     gt1l  \n",
       "184   675852.0     gt1r  \n",
       "185   679715.0     gt2l  \n",
       "186   683572.0     gt2r  \n",
       "187   687446.0     gt3l  \n",
       "188   691356.0     gt3r  \n",
       "\n",
       "[189 rows x 8 columns]"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "IntersectionsSort = Intersections.sort_values(by=['t_ATL06', 'gt_ATL06'])\n",
    "IntersectionsSort.reset_index()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Compute slope between adjacent intersections of beam pairs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/srv/conda/lib/python3.6/site-packages/ipykernel_launcher.py:11: RuntimeWarning: invalid value encountered in greater\n",
      "  # This is added back by InteractiveShellApp.init_path()\n",
      "/srv/conda/lib/python3.6/site-packages/ipykernel_launcher.py:14: RuntimeWarning: invalid value encountered in greater\n",
      "  \n"
     ]
    }
   ],
   "source": [
    "InterX = IntersectionsSort.values\n",
    "InterX = InterX\n",
    "\n",
    "Dist = np.diff(IntersectionsSort['dist_along'].values)\n",
    "Dist[Dist == 0] = float('NaN')\n",
    "InterXslopeATL06 = np.diff(IntersectionsSort['z_ATL06'].values)/Dist\n",
    "InterXslopeATM = np.diff(IntersectionsSort['ATM_elev'].values)/Dist\n",
    "\n",
    "# i = 0\n",
    "# for i in Dist():\n",
    "InterXslopeATL06[np.abs(Dist) > 150] = float('NaN')\n",
    "InterXslopeATL06 = np.append(InterXslopeATL06,[0])\n",
    "\n",
    "InterXslopeATM[np.abs(Dist) > 150] = float('NaN')\n",
    "InterXslopeATM = np.append(InterXslopeATM,[float('NaN')])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([122581.17068851, 122647.058967  , 125810.12970578, 125875.30445519,\n",
       "        80573.94429394,  77393.2937659 ,  67655.90287629,  67687.24009683,\n",
       "        64607.36088144,  64484.43299646,  61379.68549351,  61315.68444139,\n",
       "        89377.26506363,  89479.46460643,  92780.62748277,  92848.52269775,\n",
       "        96176.15302596,  96241.6091144 , 121954.02897127, 121854.85171978,\n",
       "       118653.4943702 , 118588.41551142, 115361.06654741, 115295.19138123,\n",
       "       105596.02917436, 105001.33969727, 102145.2482091 , 102080.40453568,\n",
       "        98960.11443049,  98894.60315521, 127917.08666673, 127917.08666673,\n",
       "        89241.05814438,  89172.93531811,  86031.58538731,  85963.53630899,\n",
       "        82864.46615351,  82798.52326247, 111746.23718542, 111812.54554675,\n",
       "       114966.47851405, 115032.17091117, 118164.36081161, 118262.38014119,\n",
       "        73136.80798326,  73070.49437217,  69782.28637025,  69782.28637025,\n",
       "        66747.76440998,  66654.49722872,  95027.94786504,  95126.69047093,\n",
       "        98401.58285999,  98467.48496915, 101756.03963429, 101820.94690383,\n",
       "        56887.35883001,  77789.16581823,  77854.99932367,  81275.30590324,\n",
       "        81371.24257593,  84845.20239431,  84912.84595462,  66345.52456471,\n",
       "       127486.93809309, 127420.79896681, 124218.38469648, 124153.30184889,\n",
       "       120931.50264699, 120833.06312449, 110916.63405716, 110817.08451428,\n",
       "       107630.52994006, 107565.17105679, 104337.46869381, 104271.12913349,\n",
       "        94598.50385927,  94532.098478  ,  91419.45740779,  91351.44257503,\n",
       "        88218.13185529,  88149.91935329, 117145.36688242, 117211.45768173,\n",
       "       120734.65546811, 120734.65546811, 123566.08462848, 123664.20130541,\n",
       "        78542.75837285,  78477.56091282,  75329.36382753,  75262.54211613,\n",
       "        72106.37152771,  72006.79300959, 100653.13212202, 100718.02073524,\n",
       "       104105.45509818, 104171.68169085, 107368.96793027, 107434.35232355,\n",
       "        62440.10778829,  62375.79312765,  59263.9902956 ,  59166.87555458,\n",
       "        83731.35049768,  83798.64042531,  87124.39858548,  87192.89529248,\n",
       "        90500.89031737,  90568.87727088,  62600.70517446,  62664.81194595,\n",
       "        66161.51528798,  66253.41268373,  69782.28637025,  69782.28637025,\n",
       "       119238.20173757, 119108.39302751, 115954.83147881, 112638.37188558,\n",
       "       112506.5738387 , 102696.9872489 , 102632.05402848,  99515.58578885,\n",
       "        99450.33337481,  96307.01017982,  96208.91067835, 119821.9198431 ,\n",
       "       119919.32658794, 123041.63600503, 123107.36914084, 126300.08907372,\n",
       "       126365.60836509,  86611.37813037,  86508.89529508,  83396.01070231,\n",
       "        83329.21995641,  80222.55545228,  80126.45824808,  70490.59491212,\n",
       "        70425.53527635,  67279.2925908 ,  67216.56422036,  64083.16574864,\n",
       "        64021.15144708,  86543.03637625,  86645.5283075 ,  89922.26734437,\n",
       "        89990.39154484,  93289.10054921,  93356.8377184 ,  68777.51710699,\n",
       "        68777.51710699,  72106.37152771,  72172.78972239,  75897.32347739,\n",
       "        75997.504104  , 124705.58492095, 124640.68358572, 121425.52043149,\n",
       "       121359.53182225, 118164.36081161, 118098.94385679, 108153.35724538,\n",
       "       108088.01303411, 104835.60704015, 104769.18250342, 101658.70746597,\n",
       "       101593.79643814, 125289.79523215, 125354.74992622,  91929.7715985 ,\n",
       "        91861.69277383,  88729.7387504 ,  88661.51037499,  85556.00106398,\n",
       "        85454.32105671, 109036.35594819, 109134.72378506, 112275.63637323,\n",
       "       112341.68466611, 115492.85002432, 115591.70698964,  92270.3645112 ,\n",
       "        92338.47912381,  95651.99666426,  95717.57891499,  98960.11443049,\n",
       "        99025.59014835])"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "IntersectionsSort['dist_along'].values"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Add 90m slope arrays back into IntersectionsSort and save to csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>dist_along</th>\n",
       "      <th>ATM_elev</th>\n",
       "      <th>idx_ATM</th>\n",
       "      <th>z_ATL06</th>\n",
       "      <th>t_ATL06</th>\n",
       "      <th>idx_ATL06</th>\n",
       "      <th>gt_ATL06</th>\n",
       "      <th>slope_ATM</th>\n",
       "      <th>slope_ATL06</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>160</th>\n",
       "      <td>122622.959615</td>\n",
       "      <td>44.03935</td>\n",
       "      <td>3314.0</td>\n",
       "      <td>42.769034</td>\n",
       "      <td>2018-10-18 15:53:52</td>\n",
       "      <td>617767.0</td>\n",
       "      <td>gt1l</td>\n",
       "      <td>-0.002130</td>\n",
       "      <td>-0.012068</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>161</th>\n",
       "      <td>122685.347575</td>\n",
       "      <td>43.90645</td>\n",
       "      <td>3316.0</td>\n",
       "      <td>42.016131</td>\n",
       "      <td>2018-10-18 15:53:52</td>\n",
       "      <td>621070.0</td>\n",
       "      <td>gt1r</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>162</th>\n",
       "      <td>125829.732109</td>\n",
       "      <td>35.31125</td>\n",
       "      <td>3416.0</td>\n",
       "      <td>34.973022</td>\n",
       "      <td>2018-10-18 15:53:52</td>\n",
       "      <td>624014.0</td>\n",
       "      <td>gt2l</td>\n",
       "      <td>-0.003442</td>\n",
       "      <td>-0.031405</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>163</th>\n",
       "      <td>125892.855741</td>\n",
       "      <td>35.09395</td>\n",
       "      <td>3418.0</td>\n",
       "      <td>32.990604</td>\n",
       "      <td>2018-10-18 15:53:52</td>\n",
       "      <td>626689.0</td>\n",
       "      <td>gt2r</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>80616.609191</td>\n",
       "      <td>275.81145</td>\n",
       "      <td>2136.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2018-10-21 05:21:45</td>\n",
       "      <td>205271.0</td>\n",
       "      <td>gt2r</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        dist_along   ATM_elev  idx_ATM    z_ATL06             t_ATL06  \\\n",
       "160  122622.959615   44.03935   3314.0  42.769034 2018-10-18 15:53:52   \n",
       "161  122685.347575   43.90645   3316.0  42.016131 2018-10-18 15:53:52   \n",
       "162  125829.732109   35.31125   3416.0  34.973022 2018-10-18 15:53:52   \n",
       "163  125892.855741   35.09395   3418.0  32.990604 2018-10-18 15:53:52   \n",
       "51    80616.609191  275.81145   2136.0        NaN 2018-10-21 05:21:45   \n",
       "\n",
       "     idx_ATL06 gt_ATL06  slope_ATM  slope_ATL06  \n",
       "160   617767.0     gt1l  -0.002130    -0.012068  \n",
       "161   621070.0     gt1r        NaN          NaN  \n",
       "162   624014.0     gt2l  -0.003442    -0.031405  \n",
       "163   626689.0     gt2r        NaN          NaN  \n",
       "51    205271.0     gt2r        NaN          NaN  "
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "IntersectionsSort = IntersectionsSort.assign(slope_ATM= InterXslopeATM)\n",
    "IntersectionsSort = IntersectionsSort.assign(slope_ATL06 = InterXslopeATL06)\n",
    "IntersectionsSort.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Save to file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "IntersectionsSort.to_csv(OutputFilename,index=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
